package cn.edu.scau.serviceImpl;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import cn.edu.scau.dao.PictureArticleDao;
import cn.edu.scau.entity.PictureArticle;
import cn.edu.scau.entity.Work;
import cn.edu.scau.service.PictureArcticleService;

/**
 * 图文的业务逻辑层
 * 
 * @author cxywan
 *
 */
@Service("pictureArcticleServiceImpl")
public class PictureArticleServiceImpl implements PictureArcticleService<PictureArticle> {

	/**
	 * 持久化层
	 */
	@Autowired
	private PictureArticleDao pictureArticleDao;

	public PictureArticleDao getPictureArticleDao() {
		return pictureArticleDao;
	}

	public void setPictureArticleDao(PictureArticleDao pictureArticleDao) {
		this.pictureArticleDao = pictureArticleDao;
	}

	/**
	 * 保存图文信息
	 * 
	 * @param entity
	 *            图文实体
	 */
	@Override
	public void add(PictureArticle entity) {

		this.getPictureArticleDao().save(entity);
	}

	/**
	 * 删除图文信息
	 * 
	 * @param entity
	 *            图文实体
	 */
	public boolean delete(PictureArticle entity,Integer id) {

		if (this.getPictureArticleDao().find(PictureArticle.class,id) != null) {
			this.getPictureArticleDao().delete(entity);
			return true;
		}
		return false;
	}

	/**
	 * 删除图文信息
	 * 
	 * @param id
	 *            图文实体id
	 */
	@Override
	public boolean delete(Integer id) {

		if (this.getPictureArticleDao().find(PictureArticle.class, id) != null) {
			this.getPictureArticleDao().delete(PictureArticle.class, id);
			return true;
		}
		return false;
	}

	/**
	 * 更新图文实体
	 * 
	 * @param entity
	 *            图文实体
	 */
	@Override
	public boolean update(PictureArticle entity,Integer id) {

		if (this.getPictureArticleDao().find(PictureArticle.class, id) != null) {
			this.getPictureArticleDao().update(entity);
			return true;
		}

		return false;

	}

	/**
	 * 根据id获得图文实体
	 * 
	 * @param id
	 *            图文实体id
	 * @return 返回图文实体
	 */
	@Override
	public PictureArticle getPictureArcticle(Integer id) {

		return this.getPictureArticleDao().find(PictureArticle.class, id);
	}

	/**
	 * 获得所有图文实体
	 * 
	 * @return 返回图文实体集合
	 */
	@Override
	public List<PictureArticle> getPictureArcticles() {

		return this.getPictureArticleDao().findAll(PictureArticle.class);
	}

	@Override
	public List showTheEntity(String type, Integer columnId, Integer id, Integer pageNo, boolean frontOrBackground) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public long countTheEntityNum(Integer columnId, Integer pageSize, boolean frontOrBackground) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public List<String> saveImage(MultipartFile[] files, HttpServletRequest request, String releaseDate) {
		// TODO Auto-generated method stub
		return null;
	}

}
